package com.kung.qvs.data.source.http;

import com.kung.qvs.data.source.HttpDataSource;
import com.kung.qvs.data.source.http.service.JtApiService;
import com.kung.qvs.entity.BaseResultBean;
import com.kung.qvs.entity.DemoEntity;
import com.kung.qvs.entity.GarbageTypeBean;
import com.kung.qvs.entity.KRecordWeight;
import com.kung.qvs.entity.ProductBean;
import com.kung.qvs.entity.ProductInfoBean;
import com.kung.qvs.entity.ProductTypeBean;
import com.kung.qvs.entity.PropInfoBean;
import com.kung.qvs.entity.ResSetInfoBean;
import com.kung.qvs.entity.StatisticsBean;
import com.kung.qvs.entity.WorkerBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import me.goldze.mvvmhabit.http.BaseResponse;
import me.goldze.mvvmhabit.http.BaseResponseBean;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Field;

/**
 * Created by goldze on 2019/3/26.
 */
public class HttpDataSourceImpl implements HttpDataSource {
    private JtApiService apiService;
    private volatile static HttpDataSourceImpl INSTANCE = null;

    public static HttpDataSourceImpl getInstance(JtApiService apiService) {
        if (INSTANCE == null) {
            synchronized (HttpDataSourceImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new HttpDataSourceImpl(apiService);
                }
            }
        }
        return INSTANCE;
    }

    public static void destroyInstance() {
        INSTANCE = null;
    }

    private HttpDataSourceImpl(JtApiService apiService) {
        this.apiService = apiService;
    }


    @Override
    public Observable<BaseResultBean<List<ProductTypeBean>>> reqSynchronizeProductTypes(String orgCode, String deviceCode) {
        return apiService.reqSynchronizeProductTypes(orgCode, deviceCode);
    }

    @Override
    public Observable<BaseResultBean<List<ProductBean>>> reqSynchronizeProducts(String orgCode, String deviceCode) {
        return apiService.reqSynchronizeProducts(orgCode, deviceCode);
    }

    @Override
    public Observable<BaseResultBean<Integer>> reqAddProductBean(String orgCode, String deviceCode, String productCode, String parentId,
                                                                 String productName, String productWeight, String convertRate,
                                                                 String remark) {
        return apiService.reqAddProductBean(orgCode, deviceCode,productCode, parentId, productName, productWeight, convertRate, remark);
    }

    @Override
    public Observable<BaseResultBean<Integer>> reqUpdateProductBean(String orgCode, String deviceCode, String productCode,
                                                                    String parentId, String productName, String productWeight,
                                                                    String convertRate, String remark) {
        return apiService.reqUpdateProductBean(orgCode, deviceCode, productCode, parentId, productName, productWeight, convertRate, remark);
    }

    @Override
    public Observable<BaseResultBean<Integer>> reqDeleteProductBean(String orgCode, String deviceCode, String productCode) {
        return apiService.reqDeleteProductBean(orgCode, deviceCode, productCode);
    }

    @Override
    public Observable<BaseResultBean<List<WorkerBean>>> reqSynchronizePackers(String orgCode, String deviceCode, String roleId, String userName) {
        return apiService.reqSynchronizePackers(orgCode, deviceCode, roleId, userName);
    }

    @Override
    public Observable<BaseResultBean<Integer>> reqDeletePacker(String orgCode, String deviceCode, String userId) {
        return apiService.reqDeletePacker(orgCode, deviceCode, userId);
    }

    @Override
    public Observable<BaseResultBean<Integer>> reqAddPacker(String orgCode, String deviceCode, String userCode, String userName) {
        return apiService.reqAddPacker(orgCode, deviceCode, userCode, userName);
    }

    @Override
    public Observable<BaseResultBean<Integer>> reqUpdatePacker(String orgCode, String deviceCode, String userId,
                                                               String userCode, String userName) {
        return apiService.reqUpdatePacker(orgCode, deviceCode, userId, userCode, userName);
    }

    @Override
    public Observable<BaseResultBean<KRecordWeight>> reqUploadWeightRecord(String orgCode, String deviceCode, String productId,
                                                                           String productName, String standardWeight,
                                                                           String convertRate, String packerId, String packerAccount, String packerName,
                                                                           String weight, String amount, String printCompany, String isHang) {
        return apiService.reqUploadWeightRecord(orgCode, deviceCode, productId, productName, standardWeight, convertRate, packerId,
                packerAccount, packerName, weight, amount, printCompany, isHang);
    }

    @Override
    public Observable<BaseResultBean<List<KRecordWeight>>> reqGetWeightRecord(String orgCode, String deviceCode, String workerId,
                                                                              String beginTime, String endTime, int pageSize, int pageIndex) {
        return apiService.reqGetWeightRecord(orgCode, deviceCode, workerId, beginTime, endTime, pageSize, pageIndex);
    }

    @Override
    public Observable<BaseResultBean<StatisticsBean>> reqGetWeightRecordStatistics(String orgCode, String deviceCode) {
        return apiService.reqGetWeightRecordStatistics(orgCode, deviceCode);
    }

    @Override
    public Observable<BaseResultBean<List<KRecordWeight>>> reqGetWeightRecordStatisticsDetail(String orgCode, String deviceCode
            , String beginTime, String endTime) {
        return apiService.reqGetWeightRecordStatisticsDetail(orgCode, deviceCode, beginTime, endTime);
    }
}
